#include "module_app_interface.h"
#include "module_app_menu.h"
#include "module_app_wifi.h"

static lv_obj_t *s_desktop_obj = NULL;

void app_lv_event(lv_event_t * e)
{
    lv_event_code_t code = lv_event_get_code(e);
    char *txt = lv_event_get_user_data(e);

    if (code == LV_EVENT_CLICKED)
    {
        if(0 == strcmp(txt, "wifi")) {
            module_app_wifi_enter(s_desktop_obj);
        }
    }
}

#define APP_COUNT 1

void app_menu_start(void)
{
    s_desktop_obj = lv_obj_create(lv_scr_act());
    app_im_init_obj(s_desktop_obj, LV_OPA_100, DESKTOP_COLOR);
    lv_obj_set_size(s_desktop_obj, LV_HOR_RES, LV_VER_RES);

    lv_obj_t *app_cont = lv_obj_create(s_desktop_obj);
    app_im_init_obj(app_cont, LV_OPA_100, 0xff0000);
    lv_obj_set_size(app_cont, LV_HOR_RES, LV_VER_RES - 30);
    lv_obj_align(app_cont, LV_ALIGN_BOTTOM_MID, 0, 0);
    lv_obj_set_flex_flow(app_cont, LV_FLEX_FLOW_ROW);
    lv_obj_set_flex_align(app_cont, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START);
    lv_obj_set_style_pad_all(app_cont, 10, 0);

    for(int i = 0; i < APP_COUNT; i++)
    {
        lv_obj_t *wifi_app = lv_obj_create(app_cont);
        app_im_init_obj(wifi_app, LV_OPA_50, 0x3C3D42);
        lv_obj_set_size(wifi_app, 100, 60);
        lv_obj_set_style_radius(wifi_app, 8, 0);
        lv_obj_t *wifi_label = lv_label_create(wifi_app);
        lv_label_set_text(wifi_label, "WIFI");
        lv_obj_center(wifi_label);
        lv_obj_add_event_cb(wifi_app, app_lv_event, LV_EVENT_CLICKED, "wifi");
    }

}

